package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.provider.exceptions.CacBizException;
import com.csun.cmny.provider.model.dto.CacOldmanDto;
import com.csun.cmny.provider.service.OmcOldmanFeignApi;
import com.csun.cmny.provider.service.OmcRpcService;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Slf4j
@Transactional
public class OmcRpcServiceImpl implements OmcRpcService {

    @Resource
    private OmcOldmanFeignApi omcOldmanFeignApi;

    @Override
    public int updateOldmanByEvaluate(CacOldmanDto cacOldman) {
        try {
            Wrapper<Integer> wrapper = omcOldmanFeignApi.updateOldmanByEvaluate(cacOldman);
            if (null == wrapper) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.GL99990500);
            }
            int result = wrapper.getResult();
            return result;
        } catch (Exception e) {
            log.error("updateOldmanByEvaluate={}", e.getMessage(), e);
        }
        return 0;
    }
}
